package com.gist.cithub.comment.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.gist.cithub.comment.entity.Comment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.gist.cithub.comment.entity.RootEntity;
import com.gist.cithub.comment.service.RootService;
import com.gist.common.utils.PageUtils;
import com.gist.common.utils.R;



/**
 * 
 *
 * @author lejin
 * @email sunlightcs@gmail.com
 * @date 2021-06-12 23:54:35
 */
@RestController
@RequestMapping("comment/root")
public class RootController {
    @Autowired
    private RootService rootService;
    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = rootService.queryPage(params);
        return R.ok().put("page", page);
    }
    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		RootEntity root = rootService.getById(id);

        return R.ok().put("root", root);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody RootEntity root){
		rootService.save(root);
        return R.ok().put("comment",root);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody RootEntity root){
		rootService.updateById(root);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		rootService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }
    /**
     * 信息
     */
    @RequestMapping("/all/{serviceid}")
    public R getCommentsByServiceId(@PathVariable("serviceid") Integer serviceid){
         List<Comment> list = rootService.getCommentsByServiceId(serviceid);
        return R.ok().put("list", list);
    }



}
